package com.woniuxy.sales.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.sales.common.RedisConst;
import com.woniuxy.sales.mapper.UsersMapper;
import com.woniuxy.sales.model.entity.Categories;
import com.woniuxy.sales.model.entity.Users;
import com.woniuxy.sales.model.vo.UsersVo;
import com.woniuxy.sales.service.CategoriesService;
import com.woniuxy.sales.mapper.CategoriesMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 【车辆类别表】
*/
@Service
public class CategoriesServiceImpl extends ServiceImpl<CategoriesMapper, Categories>
    implements CategoriesService{
    @Autowired
    private CategoriesMapper categoriesMapper;
    @Autowired
    private UsersMapper usersMapper;

    private final String key = "carType:list";

    @Override
    @Cacheable(cacheNames =key, keyGenerator = "keyGenerator")
    public List<Categories> findAll() {
        return this.list();
    }

    @Override
    @Cacheable(cacheNames = RedisConst.USER_DETAIL, keyGenerator = "keyGenerator")
    public UsersVo findByUserId(Long id) {
        //调用数据层查询
        Users user = usersMapper.selectById(id);
        //复制属性
        UsersVo userVo = new UsersVo();
        BeanUtils.copyProperties(user, userVo);
        userVo.setEmail(user.getEmail());
        userVo.setPassword(user.getPassword());
        userVo.setPhone(user.getPhone());
        System.out.println("userVo = " + userVo);
        return userVo;
    }

    @Override
    public Categories findById(Long id) {
        return categoriesMapper.selectById(id);
    }
}




